/*
 * 1763. Hex Conversion
 * Given a decimal number n and an integer k, Convert decimal number n to base-k.
 * https://www.lintcode.com/problem/hex-conversion/description
 * 
 * 样例
 * Example 1:
 * Given n = 5, k = 2
 * return "101"
 * 
 * Example 2:
 * Given n = 30, k = 16
 * return "1E"
 * 
 * 2018.06.10 @jeyming
 */
package hex_conversion_1763;

public class Hex_conversion_1763 {
	/**
	 * @param n: a decimal number
	 * @param k: a Integer represent base-k
	 * @return: a base-k number
	 */
	public static String hexConversion(int n, int k) {
		// write your code here
		if(n==0)
			return "0";
		String res="";
		int remain=0;
		while(n>0){
			char c;
			remain=n%k;
			if(remain>9)
				c=(char)('A'+remain-10);
			else
				c=(char)('0'+remain);
			res=c+res;
			n=n/k;
		}
		return res;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		hexConversion(5,2);
		hexConversion(30,16);
	}

}
